{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "outputs": [],
   "source": [
    "# 逻辑回归\n",
    "#逻辑回归针对二分类，结果只有两个，形状类似一个反向的Z，因此所拟合的函数是一个 1 / 1 + a1 * a2e^ x的形式\n",
    "# 通过训练集找到上述的x1 x2的值，将 x 代入，根据结果中 为 0 的比例 为 1 的比例 综合，哪个高，预测的结果就是哪个\n",
    "from sklearn import linear_model\n"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "outputs": [],
   "source": [
    "x = [[20, 3],\n",
    "     [23, 7],\n",
    "     [31, 10],\n",
    "     [42, 13],\n",
    "     [50, 7],\n",
    "     [60, 5]]\n",
    "y = [0,\n",
    "     1,\n",
    "     1,\n",
    "     1,\n",
    "     0,\n",
    "     0]\n",
    "testX = [[28, 8]]"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[1]\n",
      "prob [[0.15084679 0.84915321]]\n"
     ]
    }
   ],
   "source": [
    "lr = linear_model.LogisticRegression()\n",
    "lr.fit(x,y)\n",
    "label = lr.predict(testX)\n",
    "print(label)\n",
    "# 预测概率为0和预测概率为1的概率\n",
    "prob = lr.predict_proba(testX)\n",
    "print(\"prob\",prob)"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}